<template>
  <!-- 歌手MV -->
  <div class="ard-am">
    <div ref="amMain" class="am-main">
      <ul class="am-main-list clearfix">
        <li class="am-main-item" v-for="item in mvs" :key="item.id">
          <mv-list :item="item" :showArtist="true"></mv-list>
        </li>
      </ul>
    </div>
    <div class="am-el-pagination" v-if="mvSize > 25">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="mvSize"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import MvList from "components/mvlist/MvList.vue";

export default {
  components: {
    MvList,
  },
  props: {
    mvSize: {
      type: Number,
      default() {
        return 0;
      },
    },
  },
  data() {
    return {
      mvs: [],
      id: "",
      currentPage: 1,
      pageSize: 25,
      listTotal: 0,
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    console.log(this.id);
    this.getArtistMv();
  },
  methods: {
    handleCurrentChange() {
      console.log(this.currentPage);
      this.getArtistMv();
      // 点击分页后，滚动到评论的头部，141为页面头部组件的高度
      document.documentElement.scrollTo({
        top: this.$refs.amMain.offsetTop + 141,
        behavior: "smooth",
      });
    },
    getArtistMv() {
      this.axios({
        /* 歌手MV接口 */
        url:
          "/artist/mv?limit=25&id=" +
          this.id +
          "&offset=" +
          (this.currentPage - 1) * 25,
      })
        .then((res) => {
          this.mvs = res.data.mvs;
          console.log(this.mvs);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.ard-am {
  padding: 10px;
}
.am-main-list {
  margin-right: -20px;
}
.am-main-item {
  float: left;
  width: 20%;
}
.am-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>